package com.chentf.nio.c3;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;

/**
 * @author chentengfei
 * @desc 阻塞模式下客户端
 * @date 2022-05-07 15:45:53
 */
public class Client02 {
    public static void main(String[] args) {
        try (SocketChannel socketChannel = SocketChannel.open()){
            //建立连接
            socketChannel.connect(new InetSocketAddress("localhost",8085));
            socketChannel.write(Charset.defaultCharset().encode("hello nio..."));
            System.out.println("waiting...");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
